
indexModule.controller('noticeList',function($scope,$http,$modal,$routeParams){
    //分页
    $scope.page = {
        page: 1,//当前页数
        limit: 10,// 每页显示多少条
        maxSize: 7 // 显示多少个分页按钮
    };

    //请求用户list
    var postData = {page:$scope.page.page,size:$scope.page.limit};
    noticelist(postData,$scope.page.page);
    function noticelist(postData,page){
        postHttp($http,config.noticeList_httpUrl,postData,function(data){
            $scope.tableData = data.data.list;
            $scope.page.page = page;
            $scope.page.total = data.data.total;// list总数量
            $scope.page.numPages = Math.ceil(data.data.total/$scope.page.limit); // 总页数， 101/20 =6, 这个分页那个自动计算的值。
        });
    };

    //点击搜索
    var hasSearch = false;
    $scope.search = function(){
        var listData = {title:$scope.title,start:$("#search_start").val(),end:$("#search_end").val(),page:1,size:$scope.page.limit};
        noticelist(listData,1);
        hasSearch = true;
    };

    //页码改变时
    $scope.pageChanged = function(){
        if(typeof(localStorage) === "object"){
            localStorage.setItem("limit",$scope.page.limit);
        };
        if(parseInt($scope.page.page) > parseInt($scope.page.numPages)){
            $scope.page.page = parseInt($scope.page.numPages);
        }else if(parseInt($scope.page.page) < 1){
            $scope.page.page = 1;
        }
        if(hasSearch){
            var postData = {title:$scope.title,start:$("#search_start").val(),end:$("#search_end").val(),page:1,size:$scope.page.limit};
        }else{
            var postData = {page:$scope.page.page,size:$scope.page.limit};
        }
        noticelist(postData,$scope.page.page);
    };

    //删除公告
    $scope.delete = function(id){
        var postData = {id:id};
        postHttp($http,config.noticeDel_httpUrl,postData,function(data){
            alert(config.delHttpMsg);
            window.location.reload();
        });
    };
});
